package de.hsb.ai.agent.analyzer;

import java.util.ArrayList;
import java.util.List;

import org.jgrapht.graph.GraphPathImpl;

import de.hsb.ai.util.map.ScotlandJadeMap;
import de.hsb.ai.util.map.ScotlandJadeMapHelper.ScotlandJadeEdge;
import de.hsb.ai.util.map.ScotlandJadeMapHelper.ScotlandJadeVertex;

public class FugitivePath extends GraphPathImpl<ScotlandJadeVertex, ScotlandJadeEdge> {
	
	private final int moveNumberOffset; 
	
	private final int previousTransport;
	
	public FugitivePath(ScotlandJadeMap graph,
			ScotlandJadeVertex startVertex, 
			ScotlandJadeVertex endVertex,
			List<ScotlandJadeEdge> edgeList, 
			double weight, int moveNumberOffset,
			int previousTransport) {
		super(graph, startVertex, endVertex, edgeList, weight);
		
		this.moveNumberOffset = moveNumberOffset;
		this.previousTransport = previousTransport;
	}

	public FugitivePath expand(ScotlandJadeEdge edge, double weight) {
		ScotlandJadeVertex endVertex = ((ScotlandJadeMap) getGraph()).get(edge.getTargetIndex(getEndVertex().getIndex()));
		List<ScotlandJadeEdge> edgeList = new ArrayList<ScotlandJadeEdge>(getEdgeList().size() + 1);
		edgeList.addAll(getEdgeList());
		edgeList.add(edge);
		return new FugitivePath(
				(ScotlandJadeMap) getGraph(), 
				getStartVertex(), endVertex, 
				edgeList, 
				getWeight() + weight, moveNumberOffset, previousTransport);
	}
	
	@Override
	public int hashCode() {
		return getEdgeList().hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == this) return true;
		return (obj instanceof FugitivePath) && obj.hashCode() == this.hashCode();
	}
	
	public int getMoveNumber() {
		return moveNumberOffset + getEdgeList().size();
	}
	
	public int getPreviousTransport() {
		return previousTransport;
	}
	
}
